package com.warm.system.controller.system;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.warm.core.domain.AjaxResult;
import com.warm.log.annotation.Log;
import com.warm.log.enums.BusinessType;
import com.warm.mybatis.core.controller.BaseController;
import com.warm.mybatis.core.page.TableDataInfo;
import com.warm.pom.satoken.utils.LoginUtils;
import com.warm.system.domain.SysNotice;
import com.warm.system.service.ISysNoticeService;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Valid;
import org.noear.solon.validation.annotation.Validated;

import java.util.List;

/**
 * 公告 信息操作处理
 *
 * @author warm
 */
@Valid
@Controller
@Mapping("/system/notice")
public class SysNoticeController extends BaseController {
    @Inject
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @SaCheckPermission("system:notice:list")
    @Get
    @Mapping("/list")
    public TableDataInfo<SysNotice> list(SysNotice notice) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @SaCheckPermission("system:notice:query")
    @Get
    @Mapping(value = "/{noticeId}")
    public AjaxResult getInfo(Long noticeId) {
        return success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @SaCheckPermission("system:notice:add")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @Post
    @Mapping
    public AjaxResult add(@Validated SysNotice notice) {
        notice.setCreateBy(LoginUtils.getUsername());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @SaCheckPermission("system:notice:edit")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @Put
    @Mapping
    public AjaxResult edit(@Validated SysNotice notice) {
        notice.setUpdateBy(LoginUtils.getUsername());
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @SaCheckPermission("system:notice:remove")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @Delete
    @Mapping("/{noticeIds}")
    public AjaxResult remove(Long[] noticeIds) {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds));
    }
}
